package com.doradance.app.home;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.doradance.R;
import com.doradance.account.utils.FragmentUtils;
import com.doradance.account.utils.ShareUtil;
import com.doradance.account.utils.VipDialogUtil;
import com.pachong.android.baseuicomponent.activity.BaseActivity;

import butterknife.OnClick;

public class AllCommensActivity extends BaseActivity {
    private String course_id;
    private boolean isLearn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        course_id = getIntent().getStringExtra("course_id");
        isLearn = getIntent().getBooleanExtra("isLearn", false);
        initToolsBar();

    }

    private void initToolsBar() {
        setTitle("会员评价");
        getCustomToolbar().addLeftImageButton(R.mipmap.back, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        AllCommentsFragment allCommentsFragment = new AllCommentsFragment(course_id,isLearn);
        FragmentUtils.replaceFragment(getSupportFragmentManager(), R.id.fl_all_comments, allCommentsFragment);
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_all_commens, null);
    }

    public static void start(Activity activity, String course_id,Boolean isLearn) {
        Intent intent = new Intent(activity, AllCommensActivity.class);
        intent.putExtra("course_id", course_id);
        intent.putExtra("isLearn",isLearn);
        activity.startActivity(intent);
    }

    @OnClick(R.id.rl_up_comments)
    public void onViewClicked() {
        if(ShareUtil.getIsMember().equals("false")){
            VipDialogUtil.DetailDialog(AllCommensActivity.this,getString(R.string.no_vip),getString(R.string.become_vip_dialog));
        } else if(ShareUtil.getIsStudy()==false){
            int b = Integer.valueOf(course_id).intValue();
            VipDialogUtil.LearnDialog(AllCommensActivity.this,getString(R.string.no_learn),getString(R.string.watch_immediate),b);
        }else{
            UpCommentsActivity.start(AllCommensActivity.this,course_id);
        }

    }

    @Override
    public View createEmptyView(LayoutInflater inflater) {
        return inflater.inflate(R.layout.empty_allcomments,null);
    }
}
